<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
		<link rel="stylesheet"  href="<%=request.getContextPath() %>/css/select2.css" />
		<link rel="stylesheet" href="<%=request.getContextPath() %>/css/uniform.css" />
  </head>
  
  <body>
  	<input type="button" class="btn btn-mini btn-info" 		value="问卷绑定" id="add">
  	<input type="button" class="btn btn-mini btn-danger" 	value="删除绑定" id="delete">
  	<input type="button" class="btn btn-mini btn-primary" value="问卷发放" id="send">
  	<input type="button" class="btn btn-mini btn-inverse" value="问卷发放结束" id="end">
  	
    <div class="accordion-group widget-box">
      <div class="widget-title">
        <ul class="nav nav-tabs">
          <li class="active"><a data-toggle="tab" href="#tab2" id="tab_2">按个人</a></li>
          <li><a data-toggle="tab" href="#tab1" id="tab_1">按单位</a></li>
        </ul>
      </div>
      <div class="widget-content tab-content">
        <div id="tab1" class="tab-pane active">
		      <div class="accordion-heading">
		        <div class="widget-title"> 
		        	<a data-parent="#collapse-group" href="#collapseGOne" data-toggle="collapse" class="collapsed">
		         	<span class="icon"><i class="icon-search"></i></span>
		          	<h5>检索条件</h5>
		          	</a> 
		        </div>
		      </div>
		      <div class="accordion-body in collapse" id="collapseGOne" style="height: auto;">
		        <div class="form-horizontal">
		        	<div class="control-group">
		              <div class="search-controls">
		              		<label class="control-label2">单位名称</label>
		              		<input type="text" placeholder="Company Name" class="span2" id="companyName" >
		              		<label class="control-label2">问卷名称</label>
		              		<input type="text" placeholder="Survey Name" class="span2" id="surveyName" >
		              		<label class="control-label2">问卷状态</label>
		              			<s:select list="#{0:'未发放',1:'发放中',2:'已结束'}" cssStyle="width:100px" name="surveyFlg" id="surveyFlg" listKey="key" listValue="value"  headerKey="" headerValue="">
		              			</s:select>
		              		<div class="button-search-right">
		              			<input type="button" class="btn btn-success" value="检  索" id="searchButton1" onclick="searchResultTab1();">
		              		</div>
		              </div>
		            </div>
		        </div>
		      </div>
        </div>
        <div id="tab2" class="tab-pane">
		      <div class="accordion-heading">
		        <div class="widget-title"> 
		        	<a data-parent="#collapse-group" href="#collapseGOne" data-toggle="collapse" class="collapsed">
		         	<span class="icon"><i class="icon-search"></i></span>
		          	<h5>检索条件</h5>
		          	</a> 
		        </div>
		      </div>
		      <div class="accordion-body in collapse" id="collapseGOne" style="height: auto;">
		        <div class="form-horizontal">
		        	<div class="control-group">
		              <div class="search-controls">
		              		<label class="control-label2">姓名</label>
		              		<input type="text" placeholder="User Name" class="span2" id="userName" >
		              		<label class="control-label2">问卷名称</label>
		              		<input type="text" placeholder="Survey Name" class="span2" id="surveyNameUser" >
		              		<label class="control-label2">问卷状态</label>
		              			<s:select list="#{0:'未发放',1:'发放中',2:'已结束'}" cssStyle="width:100px" name="surveyFlgUser" id="surveyFlgUser" listKey="key" listValue="value"  headerKey="" headerValue="">
		              			</s:select>
		              		<div class="button-search-right">
		              			<input type="button" class="btn btn-success" value="检  索" id="searchButton2" onclick="searchResultTab2();">
		              		</div>
		              </div>
		            </div>
		        </div>
		      </div>
        </div>
      </div>
    </div>

    <hr />
    <div id="divTabGrid">
    	<table id="tabGrid"></table>
      <div id="pager"></div>
    </div>
    <div id="divTabGrid2">
    <table id="tabGrid2"></table>
    <div id="pager2"></div>
    </div>
  </body>
  
		<script type="text/javascript" src="<%=request.getContextPath() %>/js/matrix.form_common.js"></script> 
		<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery/jqGridUtil.js"></script>
    <script type="text/javascript">
		var configSurveySend1 = {
	          url:'<%=request.getContextPath() %>/survey/send/surveySendList.html?doType=query&tab=1',
           	colModel:[
              		{label:'send_id',name:"send_id",index:'send_id', key:true ,hidden:true},
                		{label:'wjzt',name:"survey_flg",index:'survey_flg',hidden:true},
                		{label:'单位名称',name:"company_name",index:'company_name'},
                		{label:'问卷名称',name:"survey_name",index:'survey_name'},
                		{label:'被评估人数',name:"assess_user_counts",index:'assess_user_counts'},
                		{label:'发放问卷总数',name:"send_counts",index:'send_counts'},
                		{label:'绑定时间',name:"insert_dt",index:'insert_dt'},
                		{label:'问卷状态',name:"survey_flg_name",index:'survey_flg_name'},
                		{label:'问卷发放起止时间',name:"send_dt",index:'send_dt',width:'250px'}
           	],
           	table:"#tabGrid",
           	pager: "#pager",
           	sortname: 'insert_dt',
            sortorder: "desc",
            caption:"问卷发放信息列表"
      };
    	var configSurveySend2 = {
               	url:'<%=request.getContextPath() %>/survey/send/surveySendList.html?doType=query&tab=2',
               	colModel:[
               		{label:'send_id',name:"send_id",index:'send_id', key:true ,hidden:true},
            		  {label:'wjzt',name:"survey_flg",index:'survey_flg',hidden:true},
               		{label:'姓名',name:"assess_user_nm",index:'assess_user_nm'},
               		{label:'单位名称',name:"company_name",index:'company_name'},
               		{label:'问卷名称',name:"survey_name",index:'survey_name'},
               		{label:'发放问卷总数',name:"send_counts",index:'send_counts'},
               		{label:'绑定时间',name:"insert_dt",index:'insert_dt'},
               		{label:'问卷状态',name:"survey_flg_name",index:'survey_flg_name'},
               		{label:'问卷发放起止时间',name:"send_dt",index:'send_dt',width:'250px'}
               	],
               	table:"#tabGrid2",
               	pager: "#pager2",
               	sortname: 'insert_dt',
                sortorder: "desc",
                caption:"问卷发放信息列表"
          };
	    var tab = "2";
	    jQuery(function(){

		    // 初始化单位列表显示
				jQuery("#divTabGrid").hide();
				jQuery("#pager").hide();
			  jQuery("#divTabGrid2").show();
			  jQuery("#pager2").show();
	    	jQuery.loadGrid(configSurveySend2);

			  //问卷绑定增加
	    	jQuery("#add").bind("click",function(){
	    			showDialog("问卷绑定",728,385,"<%=request.getContextPath() %>/survey/send/addSurveySend.html");
	    	});
	    	
				//问卷绑定删除
	    	jQuery("#delete").bind("click",function(){

	    		 //选中的行
   			    var id,tabGridNow;
		    		if(tab == "1"){
		    			tabGridNow = "tabGrid";
		    		}else{
		    			tabGridNow = "tabGrid2";
		    		}
		    		
	    		//选中的行
		    	id = jQuery("#"+tabGridNow).jqGrid('getGridParam', 'selarrrow');
					if(id.length==0){
						alert("请选择您要删除的记录!");
						return false;
					}

					for (var i = 0 ; i < id.length ; i++){
						var row = jQuery("#"+tabGridNow).jqGrid('getRowData', id[i]);
						if(row.survey_flg!="0"){
							alert("请选择【未发放】的问卷!");
							return false;
						}
					}
					var url = "<%=request.getContextPath() %>/survey/send/delSurveySend.html";
					var _do = function(){
						jQuery.ajaxSetup({async:false});
						jQuery.post(url,{ids:id.toString(),tab:tab},function(data){
							alert(data.toString());
							refershGrid(tabGridNow);
						},'json');
						jQuery.ajaxSetup({async:true});
					}
					
					confirm('您确定要【删除】选择的记录吗？',_do);
	    	});

			//问卷发放
    	jQuery("#send").bind("click",function(){

    		 //选中的行
			    var id,tabGridNow;
	    		if(tab == "1"){
	    			tabGridNow = "tabGrid";
	    		}else{
	    			tabGridNow = "tabGrid2";
	    		}
	    		
    		//选中的行
	    	id = jQuery("#"+tabGridNow).jqGrid('getGridParam', 'selarrrow');
				if(id.length==0){
					alert("请选择您要发放的记录!");
					return false;
				}

				for (var i = 0 ; i < id.length ; i++){
					var row = jQuery("#"+tabGridNow).jqGrid('getRowData', id[i]);
					if(row.survey_flg!="0" && row.survey_flg!="2"){
						alert("请选择【未发放中】的问卷!");
						return false;
					}
				}

				var url = "<%=request.getContextPath() %>/survey/send/sendSurveySend.html";
				var _do = function(){
					jQuery.ajaxSetup({async:false});
					jQuery.post(url,{ids:id.toString(),tab:tab},function(data){
						alert(data.toString());
						refershGrid(tabGridNow);
					},'json');
					jQuery.ajaxSetup({async:true});
				}
				
				confirm('您确定要【发放】选择的记录吗？',_do);
    	});

			//问卷发放结束
			jQuery("#end").bind("click",function(){
		
				 	//选中的行
				    var id,tabGridNow;
		    		if(tab == "1"){
		    			tabGridNow = "tabGrid";
		    		}else{
		    			tabGridNow = "tabGrid2";
		    		}
		    		
					//选中的行
		    	id = jQuery("#"+tabGridNow).jqGrid('getGridParam', 'selarrrow');
					if(id.length==0){
						alert("请选择您要发放的记录!");
						return false;
					}
		
					for (var i = 0 ; i < id.length ; i++){
						var row = jQuery("#"+tabGridNow).jqGrid('getRowData', id[i]);
						if(row.survey_flg!="1"){
							alert("请选择【发放中】的问卷!");
							return false;
						}
					}
		
					var url = "<%=request.getContextPath() %>/survey/send/endSurveySend.html";
					var _do = function(){
						jQuery.ajaxSetup({async:false});
						jQuery.post(url,{ids:id.toString(),tab:tab},function(data){
							alert(data.toString());
							refershGrid(tabGridNow);
						},'json');
						jQuery.ajaxSetup({async:true});
					}
					
					confirm('您确定要【发放结束】选择的记录吗？',_do);
			});
	    	
				//标签切换
	    	jQuery("#tab_1").bind("click",function(){
	    		tab = "1";
	    		jQuery("#tab_2").parent("li").removeClass('active');
				  jQuery("#tab2").hide();
	    		jQuery("#tab_1").parent("li").addClass('active');
				  jQuery("#tab1").show();
				  jQuery("#divTabGrid2").hide();
				  jQuery("#pager2").hide();
					jQuery("#divTabGrid").show();
					jQuery("#pager").show();
		    	jQuery.loadGrid(configSurveySend1);
		    	searchResultTab1();
		    	
	    	});

			  //标签切换
	    	jQuery("#tab_2").bind("click",function(){
		    	tab = "2";
	    		jQuery("#tab_1").parent("li").removeClass('active');
				  jQuery("#tab1").hide();
	    		jQuery("#tab_2").parent("li").addClass('active');
				  jQuery("#tab2").show();
				  jQuery("#divTabGrid2").show();
				  jQuery("#pager2").show();
					jQuery("#divTabGrid").hide();
					jQuery("#pager").hide();
		    	jQuery.loadGrid(configSurveySend2);
		    	searchResultTab2();
	    	});
	    });

	    /**
		    * 检索Tab1
		    * @param tabId
		    * @param jsonMap
		    */
	    function searchResultTab1() {
	    	var map = {};
	    	map["company_name"] = jQuery('#companyName').val();
	    	map["survey_name"] = jQuery('#surveyName').val();
	    	map["survey_flg"] = jQuery('#surveyFlg').val();
	    	search('tabGrid',map);
	    }
	    /**
		    * 检索Tab2
		    * @param tabId
		    * @param jsonMap
		    */
	    function searchResultTab2() {
	    	var map = {};
	    	map["assess_user_nm"] = jQuery('#userName').val();
	    	map["survey_name"] = jQuery('#surveyNameUser').val();
	    	map["survey_flg"] = jQuery('#surveyFlgUser').val();
	    	search('tabGrid2',map);
	    }
	    

    </script>
</html>
